package com.chinasoft.dynamic;

import com.chinasoft.bean.Student;
import com.chinasoft.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;


import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class Test01 {

    @Test
    public void selectByIds() throws IOException {

        InputStream is = Resources.getResourceAsStream("MyTabisConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);

        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);

        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        List<Student> studentList = mapper.selectByIds(list);

        studentList.forEach(System.out::println);


    }

    @Test
    public void selectCondition() throws IOException {

        InputStream is = Resources.getResourceAsStream("MyTabisConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);

        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        Student student = new Student();
        student.setAge(23);


        List<Student> list = mapper.selectCondition(student);

        list.forEach(System.out::println);

    }
}
